using System.Collections;
using UnityEngine;

public class PowerUpController : MonoBehaviour
{
    [SerializeField] private  PowerUpType powerUpType;
    
    private GameManager gameManager;
    private float lifeTime = 7f;
    private PlayerController player;

    private enum PowerUpType
    {
        Shield,Lives
    }
    
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
        gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>();
        StartCoroutine(DestroyPowerUp());
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            if (powerUpType==PowerUpType.Shield)
            {
                player.ActivateShield();
            }
            else if (powerUpType==PowerUpType.Lives)
            {
                gameManager.AddLife(1);
            }
            Destroy(gameObject);
        }
    }
    
    IEnumerator DestroyPowerUp()
    {
        yield return new WaitForSeconds(lifeTime);
        Destroy(gameObject);
    }
}